package com.chainyoung.component_tmperson.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.chainyoung.common.utils.ConvertUtils;
import com.chainyoung.common.utils.SpannalbeStringUtils;
import com.chainyoung.common.utils.StringUtil;
import com.chainyoung.component_tmperson.R;
import com.chainyoung.component_tmperson.R2;
import com.chainyoung.component_tmperson.entity.WalletFinancing;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class FinancingProAdapter extends BaseAdapter {

    private List<WalletFinancing.ListBean> data = new ArrayList<>();
    private Context context;
    private String minIn;
    private String coinName;

    public FinancingProAdapter(Context context, List<WalletFinancing.ListBean> list, String minIn, String coinName) {
        this.context = context;
        this.data = list;
        this.minIn = minIn;
        this.coinName = coinName;
    }


    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.layout_financing_pro, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        WalletFinancing.ListBean item = data.get(position);

        viewHolder.tvRate.setText(item.getRate()+"%");
        viewHolder.tvMinBuyAmount.setText(StringUtil.subZeroAndDot(minIn) + " " + coinName.toUpperCase() + "起购");
        viewHolder.tvProType.setText(item.getType().equals("current") ? "活期增益" : item.getFixed_time() + "天");
        viewHolder.txtProInfo.setText(item.getType().equals("current") ? "划转自由" : "定期期限");
        // viewHolder.txtRisk.setText(item.getRisk_rank().equals("low") ? "低风险" : item.getRisk_rank().equals("middle") ? "中低风险" : "高风险");
        viewHolder.txtRisk.setText("无风险");
        return convertView;
    }

    static class ViewHolder {
        @BindView(R2.id.tv_rate)
        TextView tvRate;
        @BindView(R2.id.txt_rate)
        TextView txtRate;
        @BindView(R2.id.tv_min_buy_amount)
        TextView tvMinBuyAmount;
        @BindView(R2.id.txt_risk)
        TextView txtRisk;
        @BindView(R2.id.tv_pro_type)
        TextView tvProType;
        @BindView(R2.id.txt_pro_info)
        TextView txtProInfo;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
